home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 6 / ctone.zip / PIANO.C next >
Text File  |  1984-12-04  |  1KB  |  55 lines

  1. /* FILENAME: piano.c
  2.  
  3.  */
  4.  
  5. #include <stdio.h>    /* use unbuffered i/o */
  6. #include <ctype.h>
  7.  
  8. #define C  262        /* define frequencies */
  9. #define D  294
  10. #define E  330
  11. #define F  349
  12. #define G  392
  13. #define A  440
  14. #define B  494
  15. #define C2 524
  16.  
  17. main ()
  18.     {
  19.     int key, freq, tempo, time;
  20.  
  21.     puts ("Please enter the basic tempo: 10 = 1 second.");
  22.     scanf ("%d", &tempo);
  23.     printf ("%d\n\r", tempo);    /* echo input */
  24.     puts ("Thank you. Use the key row a-k to play notes.  The\n\r");
  25.     puts ("shift key doubles the duration.  A ! halts the show.");
  26.  
  27.     while ( (key = getchar()) != '!')
  28.         {
  29.         time = isupper (key) ? 2 * tempo  :  tempo;
  30.         key  = tolower (key);
  31.         switch (key)
  32.             {
  33.             case 'a':    tone ( C, time);
  34.                     break;
  35.             case 's':    tone ( D, time);
  36.                     break;
  37.             case 'd':    tone ( E, time);
  38.                     break;
  39.             case 'f':    tone ( F, time);
  40.                     break;
  41.             case 'g':    tone ( G, time);
  42.                     break;
  43.             case 'h':    tone ( A, time);
  44.                     break;
  45.             case 'j':    tone ( B, time);
  46.                     break;
  47.             case 'k':    tone ( C2, time);
  48.                     break;
  49.             default:    break;
  50.             }
  51.         }
  52.     puts ("Bye bye!\n\r");
  53.     }
  54.  
  55.